//--------------------------------------------------------------------------------
// INIT CONFIG
//--------------------------------------------------------------------------------
#include <SD.h>

void setup()
{
  Serial.begin(9600);
   while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.println("INFO: Initializing SD card...");
  pinMode(53, OUTPUT);

  if (!SD.begin(4)) {
    Serial.println("ERROR: SD Card - initialization failed.");
    return;
  }
  Serial.println("INFO: SD Card - initialization done.");

  if (SD.exists("config.txt")) {
    SD.remove("config.txt");
  }
  File configFile = SD.open("config.txt", FILE_WRITE);
  if (configFile) {
    configFile.println("CONFIGURED:true");
    configFile.println("WIFI_SSID:DSLWLAN");
    configFile.println("WIFI_PASS:go2wlan@ITERGO");
    configFile.close();
    Serial.println("INFO: config.txt created.");
  }
  else {
    Serial.println("ERROR: opening config.txt");
  }
  if (SD.exists("config.txt")) {
    Serial.println("INFO: config.txt exists.");
  }
  else {
	Serial.println("ERROR: SD Card - config.txt not found.");
  }
}

void loop()
{
  delay(3000);
}